<template>
  <div>
    <img
      class="logo"
      src="../assets/9.jpg"
      @click="$router.push({ name: 'NewHome' })"
    />
    <div class="container">
      <div class="activity-detail">
        <h1 class="title">活动详情</h1>
        <el-row :gutter="20" class="container">
          <el-col :span="16">
            <el-card class="activity-card">
              <el-image
                :src="activityList.activityPictureUrl"
                class="activity-image"
                @click="handlePreviewImage"
              ></el-image>
              <div class="activity-info">
                <h3>{{ activityList.title }}</h3>
                <p>活动内容: {{ activityList.activityContent }}</p>
                <p>服务时长: {{ activityList.activityTime }} 小时</p>
                <p>创建时间: {{ activityList.createTime | timeFormat }}</p>
                <p>更新时间: {{ activityList.updateTime | timeFormat }}</p>
              </div>
            </el-card>
          </el-col>
        </el-row>
        <el-dialog
          :visible.sync="previewVisible"
          width="30%"
          class="preview-dialog"
        >
          <img
            :src="activityList.activityPictureUrl"
            alt="活动图片"
            class="preview-image"
          />
        </el-dialog>
      </div>
    </div>
  </div>
</template>

<script>
import request from "@/utils/request";

export default {
  name: "ActivityDetail",
  data() {
    return {
      activityList: [],
      previewVisible: false, // 控制图片预览的显示与隐藏
    };
  },
  created() {
    this.id = this.$route.query.id;
    this.load();
  },
  methods: {
    load() {
      request.getRequest(`/api/activity/detail/${this.id}`).then((res) => {
        if (res.data.code === 0) {
          this.activityList = res.data.data;
        } else {
          this.$message({
            type: "error",
            message: "加载失败",
          });
        }
      });
    },
    handlePreviewImage() {
      this.previewVisible = true; // 显示图片预览
    },
  },
};
</script>

<style scoped>
.container {
  display: flex;
  justify-content: center;
  align-items: center;
}
.activity-detail {
  padding: 20px;
  background-color: #f9f9f9; /* 浅灰色背景 */
}

.title {
  text-align: center;
  margin-bottom: 20px;
  color: #333;
  text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.1); /* 文字阴影 */
}

.activity-card {
  box-shadow: 0 5px 15px rgba(0, 0, 0, 0.2); /* 更深的阴影 */
  border-radius: 8px; /* 圆角 */
  overflow: hidden; /* 隐藏溢出的内容 */
  transition: box-shadow 0.3s; /* 过渡动画 */
}

.activity-card:hover {
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3); /* 鼠标悬停时的阴影变化 */
}

.activity-image {
  width: 100%;
  height: auto;
  cursor: pointer;
  border-radius: 8px 8px 0 0; /* 图片圆角 */
  transition: transform 0.3s; /* 图片过渡动画 */
}

.activity-image:hover {
  transform: scale(1.05); /* 鼠标悬停时图片放大 */
}

.activity-info {
  padding: 20px;
  background-color: #fff; /* 白色背景 */
}

.activity-info h3 {
  margin-top: 0;
  color: #333;
}

.activity-info p {
  color: #666;
  line-height: 1.6;
}

.preview-dialog .preview-image {
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: 0 8px 20px rgba(0, 0, 0, 0.3); /* 图片预览的阴影 */
}
</style>
